<%
  java.util.Vector strSearchNames = (java.util.Vector)pageContext.getAttribute("searchnames");
  if(strSearchNames == null)
    strSearchNames = new java.util.Vector();
  String strCurSearchName = (String)pageContext.getAttribute("searchname");
  if(strCurSearchName == null)
    strCurSearchName = "";
  String strCurSearchValue = (String)pageContext.getAttribute("searchvalue");
  if(strCurSearchValue == null)
    strCurSearchValue = "";
  String strCurSearchValue1 = "";
  String strCurSearchValue2 = "";
  String comDisplay = "";
  String speDisplay = "none";
  for(int i=0;i<strSearchNames.size();i++)
  {
  	java.util.HashMap temp = (java.util.HashMap)strSearchNames.elementAt(i);
  	String colname = (String)temp.get("columnname");
  	String coltype = (String)temp.get("columntype");
  	if(strCurSearchName.length() == 0)
  	  strCurSearchName = colname;
  	if(strCurSearchName.equals(colname))
  	{
  		if(!coltype.equalsIgnoreCase("varchar"))
  		{
        comDisplay = "none";
        speDisplay = "";  		  
  		}
      int csvp = strCurSearchValue.indexOf("^");      
      if(csvp != -1 && !coltype.equalsIgnoreCase("varchar"))
      {
        strCurSearchValue1 = strCurSearchValue.substring(0,csvp);
        strCurSearchValue2 = strCurSearchValue.substring(csvp + 1);  
        strCurSearchValue = "";   		
		  }
  		if(csvp != -1 && coltype.equalsIgnoreCase("date"))
  		{
        strCurSearchValue1 = OvalTools.dateToString(strCurSearchValue1,(String)session.getAttribute("dateformat"));
        strCurSearchValue2 = OvalTools.dateToString(strCurSearchValue2,(String)session.getAttribute("dateformat"));   
  		  strCurSearchValue = "";
  	  }
  	}	
  }

  String strCurOrderByCol = (String)pageContext.getAttribute("orderbycolumn");
  if(strCurOrderByCol == null)
    strCurOrderByCol = "";
  String strCurOrderByType = (String)pageContext.getAttribute("orderbytype");
  if(strCurOrderByType == null || strCurOrderByType.length() == 0)
    strCurOrderByType = "DESC";
  Integer nCurMaxItem = (Integer)pageContext.getAttribute("maxitem");
  if(nCurMaxItem == null)
    nCurMaxItem = new Integer("1");
  Integer nCurPageNo = (Integer)pageContext.getAttribute("currentpage");
  if(nCurPageNo == null)
    nCurPageNo = new Integer("0");
  Integer nCurCount = (Integer)pageContext.getAttribute("count");
  if(nCurCount == null)
    nCurCount = new Integer(0);
  Integer nCurTotalPage = (Integer)pageContext.getAttribute("totalpage");
  if(nCurTotalPage == null)
    nCurTotalPage = new Integer(0);
  Integer nCurEndIndex = (Integer)pageContext.getAttribute("theendindex");
  if(nCurEndIndex == null)
    nCurEndIndex = new Integer(0);
  boolean bCurHasPre = false;
  boolean bCurHasNext = false;  
  if(nCurCount.intValue() != 0 && pageContext.getAttribute("haspre") != null)
    bCurHasPre = ((Boolean)pageContext.getAttribute("haspre")).booleanValue();
  if(pageContext.getAttribute("hasnext") != null)
    bCurHasNext = ((Boolean)pageContext.getAttribute("hasnext")).booleanValue();  
  int nCurRowCount = 0;
  if(nCurPageNo.intValue() < nCurTotalPage.intValue() && nCurPageNo.intValue() > 0)
    nCurRowCount = nCurMaxItem.intValue();
  else if(nCurPageNo.intValue() == nCurTotalPage.intValue() && nCurTotalPage.intValue() != 0)
  {
    nCurRowCount = nCurCount.intValue()%nCurMaxItem.intValue();
    if(nCurRowCount == 0)
      nCurRowCount = nCurMaxItem.intValue();
  }
%>

<%
  OvalCustomColumn column = new OvalCustomColumn(strLanguageCode);
  java.util.Vector searchList = (java.util.Vector)column.getSearchableList(strTableName,strSearchNames);
  if(searchList == null || searchList.size() == 0)
    searchList = strSearchNames;
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td  width="47%" >
    <table width="100%"  border="0" cellspacing="0" cellpadding="0" >
        <tr> 
          <td nowrap width="66"><%= label.getLabelName("L_QuickGoTo") + label.getLabelName("L_Colon") %></td>
          <td width="10">
            <select name="searchnamealias" onchange="javascript:changeSearchName()">
            <logic:iterate id="searchid" collection="<%= searchList %>">
              <% 
                java.util.HashMap searchHash = (java.util.HashMap)pageContext.getAttribute("searchid"); 
                String strSelect = new String();   
                String strName = (String)searchHash.get("columnname");
                if(strName.equalsIgnoreCase(strCurSearchName))
                  strSelect = "Selected";
              %>
              <option <%=JspHelper.filterNull( strSelect )%>  value = "<%=JspHelper.filterNull( strName + "^" + searchHash.get("columntype") )%>">
                 <%=JspHelper.filterNull( searchHash.get("columndesc") )%>
              </option>
            </logic:iterate>      
            </select>
          </td>
          <td nowrap><input type="text" name="searchvalue" size="20" value="<%=JspHelper.filterNull( strCurSearchValue )%>" style="display:<%=JspHelper.filterNull( comDisplay )%>">
            <span id="spec" style="display:<%=JspHelper.filterNull( speDisplay )%>"><input type="text" name="searchvalue1" size="20" value="<%=JspHelper.filterNull( strCurSearchValue1 )%>">--<input type="text" name="searchvalue2" size="20" value="<%=JspHelper.filterNull( strCurSearchValue2 )%>" ></span>
         </td>
         <td width="6"><a href="javascript:page_summary('search')"><img src="<%= ConstantProp.DEFAULT_ROOT_PATH %>/images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a></td>
         <td width="200"></td>
      </tr>
    </table>
    <input type="hidden" name="searchname" value="<%=JspHelper.filterNull( strCurSearchName )%>">
    <input type="hidden" name="theendindex" value="<%=JspHelper.filterNull( nCurEndIndex )%>">
    <input type="hidden" name="maxitem" value="<%=JspHelper.filterNull( nCurMaxItem )%>">
    <input type="hidden" name="pageaction">
    <input type="hidden" name="orderbycolumn" value="<%=JspHelper.filterNull( strCurOrderByCol )%>">
    <input type="hidden" name="orderbytype" value="<%=JspHelper.filterNull( strCurOrderByType )%>">
    <input type="hidden" name="totalpage" value="<%=JspHelper.filterNull( nCurTotalPage )%>">     
    <input type="hidden" name="rowcount" value="<%=JspHelper.filterNull( nCurRowCount )%>">         
    <input type="hidden" name="ispasscheck">
    
    </td>
    <td class="td_right" width="53%">
      <% if(bCurHasPre){ %><span class="td_right"><a href="javascript:page_summary('pre')"><img src="<%= ConstantProp.DEFAULT_ROOT_PATH %>/images/<%= strLanguageCode %>/Pre.gif" border="0" style="border: 0 solid #000000"></a></span><%}%> 
      <% if(bCurHasNext){ %><a href="javascript:page_summary('next')"><img src="<%= ConstantProp.DEFAULT_ROOT_PATH %>/images/<%= strLanguageCode %>/next.gif" style="border: 0 solid #000000" border="0"></a><%}%> 
    </td>
  </tr>
  <tr> 
    <td colspan="3" class="summary_top"></td>
  </tr>
</table>
      
<script>
var dateFormat;
var label;
var messages;

function changeSearchName()
{
  document.all.item("searchvalue").value = "";    
  document.all.item("searchvalue1").value = "";    
  document.all.item("searchvalue2").value = "";    
  var searchname = document.all.item("searchnamealias").value;
  var arr = searchname.split("^");  
  var searchtype = arr[1];
  if(document.all.item("spec") != null && document.all.item("searchvalue") != null  && document.all.item("searchvalue1") != null && document.all.item("searchvalue2") != null)
  { 
    if(searchtype == "date" || searchtype == "double" || searchtype == "integer")
    {     
      document.all.item("spec").style.display = "";
      document.all.item("searchvalue").style.display = "none";    
    }else{
      document.all.item("spec").style.display = "none";
      document.all.item("searchvalue").style.display = "";    
    }
  }
}
function summaryPrepare(form,actionvalue,orderbyname)
{
  if(opener == null)
  {
    dateformat = top.topFrame.dateformat;
    label = top.topFrame.labelname;
    messages = top.topFrame.message;
  }
  else if(opener.top.topFrame != null)
  {
    dateformat = opener.top.topFrame.dateformat;
    label = opener.top.topFrame.labelname;
    messages = opener.top.topFrame.message;
  }  
  else if(opener.opener.top.topFrame != null)
  {
    dateformat = opener.opener.top.topFrame.dateformat;
    label = opener.opener.top.topFrame.labelname;
    messages = opener.opener.top.topFrame.message;
  }
    
  var summaryflag = true;
  if(form.searchnamealias != null && form.searchvalue != null && form.searchvalue1 != null && form.searchvalue2 != null)
  { 
  	var valString = form.searchnamealias.value;
    var arr = valString.split("^");  
    form.searchname.value = arr[0];
    var searchtype = arr[1];
    if(searchtype == "date" || searchtype == "Date")
    {
      var val1 = dateTransform(form.searchvalue1.value,'yyyy-MM-dd',dateformat);
      var val2 = dateTransform(form.searchvalue2.value,'yyyy-MM-dd',dateformat);
      if(val1 < 0 || val2 < 0)
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_DATE"),"%s",label.Item("L_QuickSearch")));
        form.searchvalue.value = "";
        summaryflag = false;
      }
      else
        form.searchvalue.value = val1 + "^" + val2;
    }
    else if(searchtype == "integer" || searchtype == "Integer")
    {
      if(!isInteger(form.searchvalue1.value) || !isInteger(form.searchvalue2.value))
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_INT"),"%s",label.Item("L_QuickSearch")));
        form.searchvalue.value = "";
        summaryflag = false;
      }
      else
        form.searchvalue.value = form.searchvalue1.value + "^" + form.searchvalue2.value;
    }
    else if(searchtype == "double" || searchtype == "Double")
    {
      if(!isNumeric(form.searchvalue1.value) || !isNumeric(form.searchvalue2.value))
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_NUMBER"),"%s",label.Item("L_QuickSearch")));
        summaryflag = false;
      }
      else
        form.searchvalue.value = form.searchvalue1.value + "^" + form.searchvalue2.value;
    }
  }
  if(actionvalue == "orderby")
    editform = page_orderby(form,orderbyname);
  else if(actionvalue == "jumppage")
    editform = page_jump(form);
  else if(actionvalue == "pre")
    editform = page_pre(form);
  else if(actionvalue == "next")
    editform = page_next(form);        
  else if(actionvalue == "first")  
    editform = page_first(form);
  else if(actionvalue == "last")
    editform = page_last(form); 
  else if(actionvalue == "search")
    editform = page_search(form); 
  if(summaryflag)  
    return editform;
  else
    return summaryflag;
}
function page_pre(form)
{
  form.pageaction.value="Pre";
  return form;
}
function page_next(form)
{
  form.pageaction.value="Next";
  return form;
}
function page_first(form)
{
  form.pageaction.value="Jump";
  form.jumppage.value = "-2"
  return form;  
}
function page_last(form)
{
  form.pageaction.value="Jump";
  form.jumppage.value = "-1"
  return form;
}
function page_jump(form)
{
  form.pageaction.value="Jump";
  if(form.jumppage.value <= 0)
    form.jumppage.value = 1;
  if(form.jumppage.value - form.totalpage.value > 0)
    form.jumppage.value = form.totalpage.value;
  return form;
}

function page_orderby(form,ordercol)
{
  form.pageaction.value = "OrderBy";
  if(form.orderbycolumn.value.toUpperCase() == ordercol.toUpperCase())
  {
    if(form.orderbytype.value.toUpperCase() == "ASC")
      form.orderbytype.value = "DESC";
    else
      form.orderbytype.value = "ASC";
  }
  else
    form.orderbycolumn.value = ordercol;
  return form;
}
function page_search(form)
{
  form.pageaction.value="OrderBy";
  return form;
}

</script>
